import 'package:example_package/example_package.dart';
import 'package:example_package/listener/package_package2_listener.dart';
import 'package:example_package/router/example_package_routes.dart';
import 'package:example_package/util/widget_util.dart';
@RikiArgumentImport()
import 'package:flutter/material.dart';
import 'package:riki_router/riki_router.dart';

@RikiRoute(
  name: '/package/2',
  routeName: 'package2页面',
  pageRouteType: PageRouteType.cupertino,
)
class Package2Page extends StatelessWidget with Package2Listener {
  const Package2Page({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ExamplePackage.instance.addPackageListener(this);
    RikiPage? route = RikiRouterDelegate.of(context).find(this);
    return Scaffold(
      appBar: buildAppBar('PACKAGE 2'),
      body: ListView(
        children: [
          Container(
            alignment: Alignment.center,
            height: 44,
            child: Text(route?.routeName ?? ''),
          ),
          buildListTile('进入PACKAGE1_2', () {
            RikiRouterDelegate.of(context).pushUri('/package1/2');
          }),
          buildListTile('返回首页', () {
            RikiRouterDelegate.of(context).popUntilWithNamed('/');
            RikiEvent.instance.fire(RikiEventType('PACKAGE2'), '发送了事件');
          }),
        ],
      ),
    );
  }

  @override
  void package2(arguments) {
    print('package2:$arguments');
  }
}
